package com.hopu.controller;


import com.hopu.pojo.Organization;
import com.hopu.pojo.R;
import com.hopu.service.OrganizationService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author YwaiX
 * @since 2024-09-12
 */
@RestController
@RequestMapping("/organization")
public class OrganizationController {
    @Resource
    private OrganizationService organizationService;

    /**
     * 获取组织列表
     * @return
     */
    @GetMapping("getList")
    public R getOrganList() {
        return R.ok(this.organizationService.getOrganizaList());
    }

    @DeleteMapping
    public R deleteOrgan(@RequestParam("id") int id) {
        return R.ok("删除成功！",organizationService.removeById(id));
    }

    /**
     * 修改组织
     * @RequestBody: 将请求体中的json数据转换为java对象
     * @param organization
     */
    @PostMapping("update")
    public R updateOrgan(@RequestBody Organization organization) {
        System.out.println(organization);
        return R.ok("修改成功！",organizationService.updateById(organization));
    }
    
    /**
     * 添加组织
     * @param organization
     * @return
     */
    @PostMapping("add")
    public R addOrgan(@RequestBody Organization organization){
        System.out.println(organization);
        organizationService.insert(organization);
        return R.ok("添加成功");
    }


    /**
     * 修改组织状态
     * @param id
     * @param status
     * @return
     */
    @GetMapping("updateStatus")
    public R updateStatus(Integer id, Integer status){
        organizationService.updateStatus(id, status);
        return R.ok("修改成功");
    }
}
